package com.huika.renrench.control.investment.adapter;

import android.content.Context;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huika.renrench.R;
import com.huika.renrench.control.common.base.BaseAda;
import com.huika.renrench.support.bean.BorrowDetailBean;
import com.huika.renrench.utils.DateTimeTool;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class InvestmentGoAdapter extends BaseAda<BorrowDetailBean> {

	private SparseArray<View> map = new SparseArray<View>();
	private DisplayImageOptions options;
	
	public InvestmentGoAdapter(Context context) {
		super(context);
		options = new DisplayImageOptions.Builder()
		.showImageOnLoading(R.drawable.icon_default_small)
		// resource or drawable
		.showImageForEmptyUri(R.drawable.icon_default_small)
		.showImageOnFail(R.drawable.icon_default_small)
		.cacheInMemory(true)// 开启内存缓存
		.cacheOnDisk(true) // 开启硬盘缓存
		.resetViewBeforeLoading(true).build();
	}

	private static class ViewHolder {
		ImageView img;
		TextView merchant_name;
		TextView money_detail;
		TextView time_detail;
		TextView address;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null; 
		if(map.get(position) == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_invest_go, null);
			holder.img = (ImageView) convertView.findViewById(R.id.img);
			holder.merchant_name = (TextView) convertView.findViewById(R.id.merchant_name);
			holder.money_detail = (TextView) convertView.findViewById(R.id.money_detail);
			holder.time_detail = (TextView) convertView.findViewById(R.id.time_detail);
			holder.address = (TextView) convertView.findViewById(R.id.address);
			convertView.setTag(holder);
			final int p = position;
			map.put(p, convertView);
		} else {
			convertView = map.get(position);
			holder = (ViewHolder) convertView.getTag();
		}
		BorrowDetailBean bean = group.get(position);
		ImageLoader.getInstance().displayImage(bean.getDefaultImage(),
				holder.img, options);
		holder.merchant_name.setText(bean.getTitle());
		holder.money_detail.setText(bean.getTargetAmount() + "元");
		holder.time_detail.setText(DateTimeTool.getTimeWithFormat(Long.parseLong(bean.getCreateTime()), "yyyy.MM.dd"));
		holder.address.setText(bean.getShopAddress());
		return convertView;
	}

}
